package cn.loioi.util.page.datatable;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.ui.Model;

import com.github.pagehelper.PageInfo;

/**
 * <br>
 * (c) Copyright 2016 by <br>
 * @description :DataTable 返回类型 <br>
 * @file_name :DataTableResponse.java <br>
 * @system_name :cmp-web <br>
 * @author :yyzh <br>
 * @创建时间 :2016年8月24日 下午5:25:01
 */
public class DataTableResponse {
	private Integer draw;
	private Long recordsTotal;
	private Long recordsFiltered;
	private List<?> data = new ArrayList<>();

	public Integer getDraw() {
		return draw;
	}

	public void setDraw(Integer draw) {
		this.draw = draw;
	}

	public Long getRecordsTotal() {
		return recordsTotal;
	}

	public void setRecordsTotal(Long recordsTotal) {
		this.recordsTotal = recordsTotal;
	}

	public Long getRecordsFiltered() {
		return recordsFiltered;
	}

	public void setRecordsFiltered(Long recordsFiltered) {
		this.recordsFiltered = recordsFiltered;
	}

	public List<?> getData() {
		return data;
	}

	public void setData(List<?> data) {
		this.data = data;
	}

	/**
	 * 推出数据
	 * @param model
	 */
	public void flush(Model model) {
		model.addAttribute("data", this.data);
		model.addAttribute("draw", this.draw);
		model.addAttribute("recordsTotal", this.recordsTotal);
		model.addAttribute("recordsFiltered", this.recordsFiltered);
	}

	/**
	 * 返回map对象
	 * @return
	 */
	public Map<String, Object> map() {
		Map<String, Object> map = new HashMap<>();
		map.put("data", this.data);
		map.put("draw", this.draw);
		map.put("recordsTotal", this.recordsTotal);
		map.put("recordsFiltered", this.recordsFiltered);
		return map;
	}

	public void setData(PageInfo<?> pageInfo) {
		this.recordsFiltered = pageInfo.getTotal();
		this.recordsTotal = pageInfo.getTotal();
		this.data = pageInfo.getList();
	}
}
